/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lib;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;

/**
 *
 * @author ismail
 */
public class db extends dbInfo {

    Connection con = null;
    Connection con2 = null;
    Statement st = null;
    ResultSet res = null;
    ResultSetMetaData resMetaData = null;
    String tableName = "";
    String Where = "";
    String cdata = "";
    String Result = "";
    String type = "";
    //  lib.tools.Utils utils = new lib.tools.Utils();
    // HttpServletResponse response=null;
//public class operations extends HttpServlet implements lib.Options.DbInfo 

    public String outPrint(HttpServletResponse response, String data) throws IOException, JspException {
        String fdd = "";

        PrintWriter out = response.getWriter();
        /*
         * try { // out.print(data); } catch (IOException ex) { //
         * Logger.getLogger(Utils.class.getName()).log(Level.SEVERE, null, ex);
         * fdd=ex.getMessage();
         *
         * }
         */
        return fdd;

    }

    public void settableName(String tableName) {
        this.tableName = tableName;
    }

    public void setcdata(String cdata) {
        this.cdata = cdata;
    }

    public void setWhere(String setWhere) {
        this.tableName = Where;
    }

    public void setType(String Type) {
        this.type = Type;
    }

    public Object getResult() {
        Object returnOject = null;
        if (this.type == "get_data") {
            returnOject = this.getData(this.tableName, this.cdata, this.Where);
        }
        return returnOject;

    }

    public String openCon() {


        String retdata = "";
        try {
            Class.forName("com.mysql.jdbc.Driver");
            con = DriverManager.getConnection(connectionString, dbUser, dbPassword);
        } catch (SQLException ex) {
            retdata += ex.getMessage();
            //utils.outPrint(response, ex.getMessage());
            Logger.getLogger(db.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            retdata += "xxx" + ex.getMessage();
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
        }
        return retdata;
    }

    public void closeConNewcon(java.sql.Connection mycon) {
        try {

            if (mycon != null) {
                mycon.close();
                mycon = null;
            }
        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
        }


    }

    public void closeCon() {
        try {
            if (res != null) {
                res.close();
                res = null;
            }
            if (st != null) {
                st.close();
                st = null;
            }
            if (con != null) {
                con.close();
                con = null;
            }
        } catch (SQLException ex) {
            //utils.outPrint(response, ex.getMessage());
        }


    }

    ////////////////////////////////getDataToResultSet
    private String creatviewFull(String viewName, String AS, String from, String Where) {
        this.openCon();
        String retunData = "";

        try {
            Statement st2 = con.createStatement();
            st2.executeUpdate("DROP VIEW IF EXISTS `" + viewName + "`;");
            String sql = "";
            if (Where.equals("")) {
                sql = "CREATE VIEW  `" + viewName + "` as SELECT " + AS + "  FROM " + from;
            } else {
                sql = "CREATE VIEW  `" + viewName + "` as SELECT " + AS + " FROM " + from + " WHERE " + Where;
            }
            st2.executeUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
            retunData = ex.getMessage();

            //utils.outPrint(response, ex.getMessage());
        }
        this.closeCon();
        return retunData;
    }

    public String creatview(String viewName, String AS, String from) {

        return this.creatviewFull(viewName, AS, from, "");
    }

    public String creatview(String viewName, String AS, String from, String Where) {
        return this.creatviewFull(viewName, AS, from, Where);
    }

    private String creatviewFullNOCON(String viewName, String AS, String from, String Where) {
        //   this.openCon();
        String retunData = "";

        try {
            Statement st2 = con.createStatement();
            st2.executeUpdate("DROP VIEW IF EXISTS `" + viewName + "`;");
            String sql = "";
            if (Where.equals("")) {
                sql = "CREATE VIEW  `" + viewName + "` as SELECT " + AS + "  FROM " + from;
            } else {
                sql = "CREATE VIEW  `" + viewName + "` as SELECT " + AS + " FROM " + from + " WHERE " + Where;
            }
            st2.executeUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
            retunData = ex.getMessage();
        }
        //  this.closeCon();
        return retunData;
    }

    public String creatviewNOCON(String viewName, String AS, String from) {

        return this.creatviewFullNOCON(viewName, AS, from, "");
    }

    public String creatviewNOCON(String viewName, String AS, String from, String Where) {
        return this.creatviewFullNOCON(viewName, AS, from, Where);
    }

    ////////////////////////////////getDataToResultSet
    ////////////////////////////////getDataToResultSet
    public String getDataTest(String table, String Cdata, String Where) {
        //  this.openCon();

        String retuenData = "";
        try {
            Statement st2 = con.createStatement();
            String sql = "";
            if (!Where.equals("")) {
                sql = "SELECT * FROM " + table + " WHERE " + Where;
            } else {

                sql = "SELECT * FROM " + table;
            }

            res = st2.executeQuery(sql);

        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());

            retuenData = ex.getMessage();

        }
        // this.closeCon();
        return retuenData;
    }

    private ResultSet getDataFull(String table, String Cdata, String Where) {
        ResultSet re = null;
        //  this.openCon();   

     
   try {


           Statement st2 = con.createStatement();
            String sql = "";
            if (!Where.equals("")) {
                sql = "SELECT * FROM " + table + " WHERE " + Where;
            } else {

                sql = "SELECT * FROM " + table;
            }

          re = st2.executeQuery(sql);

       } catch (SQLException ex) {
              Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
        }
      //   this.closeCon();
        return re;
    }

    public ResultSet getData(String table) {
        ResultSet rs = this.getDataFull(table, "*", "");
        return rs;
    }

    public ResultSet getData(String table, String Cdata) {
        ResultSet rs = this.getDataFull(table, Cdata, "");
        return rs;
    }

    public ResultSet getData(String table, String Cdata, String Where) {
        ResultSet rs = this.getDataFull(table, Cdata, Where);
        return rs;
    }

    private ResultSet getDataFullNeWcon(String table, String Cdata, String Where, java.sql.Connection mycon) {
        //  this.openCon();

        ResultSet re = null;
        try {


            Statement st2 = mycon.createStatement();
            String sql = "";
            if (!Where.equals("")) {
                sql = "SELECT * FROM " + table + " WHERE " + Where;
            } else {

                sql = "SELECT * FROM " + table;
            }

            re = st2.executeQuery(sql);

        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
        }
        // this.closeCon();
        return re;
    }

    public ResultSet getDataNeWcon(String table, java.sql.Connection mycon) {
        ResultSet rs = this.getDataFullNeWcon(table, "*", "", mycon);
        return rs;
    }

    public ResultSet getDataNeWcon(String table, String Cdata, java.sql.Connection mycon) {
        ResultSet rs = this.getDataFullNeWcon(table, Cdata, "", mycon);
        return rs;
    }

    public ResultSet getDataNeWcon(String table, String Cdata, String Where, java.sql.Connection mycon) {
        ResultSet rs = this.getDataFullNeWcon(table, Cdata, Where, mycon);
        return rs;
    }

    ////////////////////////////////getData
    ////////////////////////////////getDataToResultSet
    private ResultSetMetaData getFullMyMetaData(String table, String Cdata, String Where) {
        this.openCon();
        String[] maa = null;
        int i = 0;

        try {
            st = con.createStatement();
            if (Where != "") {
                Where = " Where " + Where;
            }
            ;

            res = st.executeQuery("SELECT " + Cdata + " FROM " + table + " " + Where);

            resMetaData = res.getMetaData();



        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
        }
        this.closeCon();
        return resMetaData;
    }

    public ResultSetMetaData getMyMetaData(String table) {
        resMetaData = this.getFullMyMetaData(table, "*", "");
        return resMetaData;
    }

    public ResultSetMetaData getMyMetaData(String table, String Cdata) {
        resMetaData = this.getFullMyMetaData(table, Cdata, "");
        return resMetaData;
    }

    public ResultSetMetaData getMyMetaData(String table, String Cdata, String Where) {
        resMetaData = this.getFullMyMetaData(table, Cdata, Where);
        return resMetaData;
    }

    ////////////////////////////////getData
    private ResultSetMetaData getFullMyMetaDataNocon(String table, String Cdata, String Where) {

        String[] maa = null;
        int i = 0;

        try {
            st = con.createStatement();
            if (Where != "") {
                Where = " Where " + Where;
            }


            res = st.executeQuery("SELECT " + Cdata + " FROM " + table + " " + Where);

            resMetaData = res.getMetaData();



        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
        }

        return resMetaData;
    }

    public ResultSetMetaData getMyMetaDataNocon(String table) {
        resMetaData = this.getFullMyMetaDataNocon(table, "*", "");
        return resMetaData;
    }

    public ResultSetMetaData getMyMetaDataNocon(String table, String Cdata) {
        resMetaData = this.getFullMyMetaDataNocon(table, Cdata, "");
        return resMetaData;
    }

    public ResultSetMetaData getMyMetaDataNocon(String table, String Cdata, String Where) {
        resMetaData = this.getFullMyMetaDataNocon(table, Cdata, Where);
        return resMetaData;
    }

    ////////////////////////////////getData
    ////////////////////////////////getFullColumn
    public int getRowCountNocon(String table, String Where) {


        int rowCount = 0;



        try {
            st = con.createStatement();
            if (!Where.equals("")) {
                Where = " Where " + Where;
            }

            res = st.executeQuery("SELECT * FROM " + table + " " + Where);
            if (res != null) {

                res.last();
                rowCount = res.getRow();
            }

        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
        }

        return rowCount;


    }

    public int getRowCountNewcon(String table, String Where, Connection con) {


        int rowCount = 0;



        try {

            ResultSet rescc = this.getDataFullNeWcon(table, "*", Where, con);
            if (rescc != null) {

                rescc.last();
                rowCount = rescc.getRow();
            }

        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
        }

        return rowCount;


    }

    public int getRowCount(String table, String Where) {

        this.openCon();
        int rowCount = 0;

        // int i = 0;

        try {
            st = con.createStatement();
            if (Where != "") {
                Where = " Where " + Where;
            }
            ;
            res = st.executeQuery("SELECT * FROM " + table + " " + Where);
            if (res != null) {

                res.last();
                rowCount = res.getRow();
            }

        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
        }




        this.closeCon();

        return rowCount;


    }

    private String[] getFullColumn(String table, String Cdata, String Where) {

        int clu_num = getRowCount(table, Where);
        this.openCon();
        String[] returnArray = null;
        int i = 0;

        try {
            st = con.createStatement();





            if (Where != "") {
                Where = " Where " + Where;
            }
            ;
            res = st.executeQuery("SELECT " + Cdata + " FROM " + table + " " + Where);
            if (res != null) {


                returnArray = new String[clu_num];


                while (res.next()) {
                    returnArray[i] = res.getString(Cdata);
                    i++;
                }
            }






        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
        }
        this.closeCon();
        return returnArray;
    }

    public String getFullColumn_test(String table, String Cdata, String Where) {

        this.openCon();
        String[] returnArray = null;
        int i = 0;

        try {
            st = con.createStatement();
            if (Where != "") {
                Where = " Where " + Where;
            }
            ;

            // res = st.executeQuery("SELECT " + Cdata + " FROM " + table + " " + Where);


            if (res != null) {
                resMetaData = res.getMetaData();

                while (res.next()) {
                    returnArray[i] = res.getString(Cdata);

                }
            }

        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
        }
        this.closeCon();
        return "SELECT " + Cdata + " FROM " + table + " " + Where;
    }

    public String[] getColumn(String table, String Cdata) {
        String[] returnData = this.getFullColumn(table, Cdata, "");
        return returnData;
    }

    public String[] getColumn(String table, String Cdata, String Where) {
        String[] returnData = this.getFullColumn(table, Cdata, Where);
        return returnData;
    }

    ////////////////////////////////getFullColumn
    private String[] getFullColumnNOCON(String table, String Cdata, String Where) {

        int clu_num = getRowCountNocon(table, Where);

        String[] returnArray = null;
        int i = 0;

        try {
            st = con.createStatement();





            if (Where != "") {
                Where = " Where " + Where;
            }
            ;
            res = st.executeQuery("SELECT " + Cdata + " FROM " + table + " " + Where);
            if (res != null) {


                returnArray = new String[clu_num];


                while (res.next()) {
                    returnArray[i] = res.getString(Cdata);
                    i++;
                }
            }






        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
        }
        // this.closeCon();
        return returnArray;
    }

    public String[] getColumnNOCON(String table, String Cdata) {
        String[] returnData = this.getFullColumnNOCON(table, Cdata, "");
        return returnData;
    }

    public String[] getColumnNOCON(String table, String Cdata, String Where) {
        String[] returnData = this.getFullColumnNOCON(table, Cdata, Where);
        return returnData;
    }

    public String getFullColumntest(String table, String Cdata, String Where) {

        int clu_num = getRowCountNocon(table, Where);

        String[] returnArray = null;
        String returnArray2 = "";
        int i = 0;
        String sql = "";
        try {
            st = con.createStatement();





            if (Where != "") {
                Where = " Where " + Where;
            }
            sql = "SELECT " + Cdata + " FROM " + table + " " + Where;


            res = st.executeQuery(sql);
            if (res != null) {


                returnArray = new String[clu_num];


                while (res.next()) {
                    returnArray[i] = res.getString(Cdata);
                    i++;
                }
            }




            returnArray2 = sql;

        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
            returnArray2 = sql + ex.getMessage();
        }
        // this.closeCon();
        return returnArray2;
    }

    ////////////////////////////////getFullColumn
    ////////////////////////////////getDataToStringarray
    private String[] getFullRow(String table, String Where) {

        this.openCon();
        String[] returnArray = null;

        try {




            ResultSet re = this.getDataFull(table, "*", Where);

            resMetaData = re.getMetaData();
            int clu_num = resMetaData.getColumnCount();
            returnArray = new String[clu_num];

            int mu = 0;

            if (re.next()) {
                for (int c = 0; c < clu_num; c++) {


                    returnArray[c] = re.getString(c + 1);


                }
            }




            /*
             * while (re.next()) { mu++; returnArray[mu - 1] =
             * res.getString(mu);
             *
             *
             * }
             */




        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
        }
        this.closeCon();
        return returnArray;
    }

    public String[] getRow(String table) {
        String[] returnData = this.getFullRow(table, "");
        return returnData;
    }

    public String[] getRow(String table, String Where) {
        String[] returnData = this.getFullRow(table, Where);
        return returnData;
    }

    public String[] getRow(String table, int id) {

        String pid = Integer.toString(id);
        String[] returnData = this.getFullRow(table, "id=" + pid);
        return returnData;
    }

    ////////////////////////////////getRow
    ////////////////////////////////getDataToStringarray
    private String[] getFullRowNocon(String table, String Where) {


        String[] returnArray = null;

        try {

            ResultSet ress = this.getDataFull(table, "*", Where);

            resMetaData = ress.getMetaData();
            int clu_num = resMetaData.getColumnCount();
            returnArray = new String[clu_num];

            int mu = 0;

            if (ress.next()) {


                for (int c = 0; c < clu_num; c++) {
                    returnArray[c] = ress.getString(c + 1);
                }
            };


            /*
             * while (ress.next()) { mu++; returnArray[mu - 1] =
             * ress.getString(mu);
             *
             *
             * }
             */



        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
        }

        return returnArray;
    }

    private String[] getFullRowNewconn(String table, String Where, Connection mycn) {


        String[] returnArray = null;

        try {

            ResultSet ress = this.getDataFullNeWcon(table, "*", Where, mycn);

            resMetaData = ress.getMetaData();
            int clu_num = resMetaData.getColumnCount();
            returnArray = new String[clu_num];

            int mu = 0;

            if (ress.next()) {


                for (int c = 0; c < clu_num; c++) {
                    returnArray[c] = ress.getString(c + 1);
                }
            }

        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
        }

        return returnArray;
    }

    public String[] getRowNewCon(String table, Connection mycn) {
        String[] returnData = this.getFullRowNewconn(table, "", mycn);
        return returnData;
    }

    public String[] getRowNewCon(String table, String Where, Connection mycn) {
        String[] returnData = this.getFullRowNewconn(table, Where, mycn);
        return returnData;
    }

    public String[] getRowNewCon(String table, int id, Connection mycn) {

        String pid = Integer.toString(id);
        String[] returnData = this.getFullRowNewconn(table, pid, mycn);
        return returnData;
    }

    public String[] getRowNocon(String table) {
        String[] returnData = this.getFullRowNocon(table, "");
        return returnData;
    }

    public String[] getRowNocon(String table, String Where) {
        String[] returnData = this.getFullRowNocon(table, Where);
        return returnData;
    }

    public String[] getRowNocon(String table, int id) {

        String pid = Integer.toString(id);
        String[] returnData = this.getFullRowNocon(table, pid);
        return returnData;
    }

    ////////////////////////////////getRow
    ////////////////////////////////getValue
    private String getFullValue(String table, String Cdata, String Where, String id) {
        this.openCon();
        String return_string = "";
        String sql = "";
        try {
            st = con.createStatement();


            if (Where != "") {

                sql = "SELECT " + Cdata + " FROM " + table + " Where " + Where;
            } else if (id != "") {

                sql = "SELECT " + Cdata + " FROM " + table + " Where id=" + id;
            } else {

                sql = "SELECT " + Cdata + " FROM " + table;
            }

            res = st.executeQuery(sql);
            if (res.next()) {


                return_string = res.getString(Cdata);
            }



        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
        }
        this.closeCon();
        return return_string;

    }

    public String getValue(String table, String Cdata, int id) {
        String pid = Integer.toString(id);
        String returnData = this.getFullValue(table, Cdata, "", pid);
        return returnData;
    }

    public String getValue(String table, String Cdata, String Where) {
        String returnData = this.getFullValue(table, Cdata, Where, "");
        return returnData;
    }
    ////////////////////////////////getValue

    private String getFullValueNocon(String table, String Cdata, String Where, String id) {

        String retData = "null";
        try {
            ResultSet rss = this.getData(table, Cdata, Where);

            while (rss.next()) {

                retData = rss.getString(Cdata);

            }

        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());

        }
        return retData;

    }

    public String getValueNocon(String table, String Cdata, int id) {
        String pid = Integer.toString(id);
        String returnData = this.getFullValueNocon(table, Cdata, "", pid);
        return returnData;
    }

    public String getValueNocon(String table, String Cdata, String Where) {
        String returnData = this.getFullValueNocon(table, Cdata, Where, "");
        return returnData;
    }
    ////////////////////////////////getValue

    ////////////////////////////////setDelete
    private String setFullDelete(String table, String Where, String id) {

        String returnStatus = "";
        this.openCon();
        try {
            st = con.createStatement();
            String sql = "";
            if (Where != "") {
                sql = "Delete  From " + table + " Where " + Where;
            } else {
                sql = "Delete  From " + table + " Where id=" + id;
            }
            st.executeUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
            returnStatus = ex.getMessage();
        }
        this.closeCon();
        return returnStatus;
    }

    public String setDelete(String table, int id) {

        String pid = Integer.toString(id);
        String returndata = this.setFullDelete(table, "", pid);
        return returndata;

    }

    public String setDelete(String table, String Where) {

        String returndata = this.setFullDelete(table, Where, "");
        return returndata;

    }
    ////////////////////////////////setDelete

    ////////////////////////////////setDelete
    private String setFullDeleteNocon(String table, String Where, String id) {

        String returnStatus = "";

        try {
            st = con.createStatement();
            String sql = "";
            if (Where != "") {
                sql = "Delete  From " + table + " Where " + Where;
            } else {
                sql = "Delete  From " + table + " Where id=" + id;
            }
            st.executeUpdate(sql);
        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
            returnStatus = ex.getMessage();
        }

        return returnStatus;
    }

    public String setDeleteNocon(String table, int id) {

        String pid = Integer.toString(id);
        String returndata = this.setFullDeleteNocon(table, "", pid);
        return returndata;

    }

    public String setDeleteNocon(String table, String Where) {

        String returndata = this.setFullDeleteNocon(table, Where, "");
        return returndata;

    }
    ////////////////////////////////setDelete

    ////////////////////////////////setUpdate
    private String setFullUpdate(String table, String[][] data, String Where, String id) {

        String valus = "";
        String sql = "";
        String er = "";
        for (int i = 0; i < data[0].length; i++) {
            String spli = ",";
            if (i == 0) {
                spli = "";
            }
            ;


            if (data[1][i].indexOf("'") == -1) {


                valus += spli + "`" + data[0][i] + "` = " + "'" + data[1][i] + "'";
            } else {

                valus += spli + "`" + data[0][i] + "` = " + data[1][i];

            }







        }
        int returnStatus = 0;
        this.openCon();

        try {
            st = con.createStatement();

            if (Where != "") {

                sql = "Update  `" + table + "`  set " + valus + " Where " + Where;
            } else {

                sql = "Update  `" + table + "`  set " + valus + " Where id=" + id;

            }
            returnStatus = st.executeUpdate(sql);

        } catch (SQLException ex) {

            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());



            er = ex.getMessage();
        }
        this.closeCon();

        return er;
    }

    public String setUpdate(String table, String[][] data, int id) {
        String pid = Integer.toString(id);
        String returndata = this.setFullUpdate(table, data, "", pid);
        return returndata;
    }

    public String setUpdate(String table, String[][] data, String Where) {
        String returndata = this.setFullUpdate(table, data, Where, "");
        return returndata;

    }

    ////////////////////////////////setUpdate
    ////////////////////////////////setUpdate
    private String setFullUpdateNocon(String table, String[][] data, String Where, String id) {

        String valus = "";
        String sql = "";
        String er = "";
        for (int i = 0; i < data[0].length; i++) {
            String spli = ",";
            if (i == 0) {
                spli = "";
            }
            ;


            if (data[1][i].indexOf("'") == -1) {


                valus += spli + "`" + data[0][i] + "` = " + "'" + data[1][i] + "'";
            } else {

                valus += spli + "`" + data[0][i] + "` = " + data[1][i];

            }







        }
        int returnStatus = 0;
        // this.openCon();

        try {
            st = con.createStatement();

            if (Where != "") {

                sql = "Update  `" + table + "`  set " + valus + " Where " + Where;
            } else {

                sql = "Update  `" + table + "`  set " + valus + " Where id=" + id;

            }
            returnStatus = st.executeUpdate(sql);

        } catch (SQLException ex) {
            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());

            er = ex.getMessage();
        }
        //  this.closeCon();

        return er;
    }

    public String setUpdateNocon(String table, String[][] data, int id) {
        String pid = Integer.toString(id);
        String returndata = this.setFullUpdateNocon(table, data, "", pid);
        return returndata;
    }

    public String setUpdateNocon(String table, String[][] data, String Where) {
        String returndata = this.setFullUpdateNocon(table, data, Where, "");
        return returndata;

    }

    ////////////////////////////////setUpdate
    ////////////////////////////////setUpdateValue
    private int setFullUpdateValueNocon(String table, String fieldName, String Value, String Where, String id) {
        String sql = "";
        int returnStatus = 0;

        String return_string = "";
        try {
            st = con.createStatement();
            if (Where != "") {
                sql = "Update  `" + table + "`  set " + fieldName + "='" + Value + "' Where " + Where;
            } else {
                sql = "Update  `" + table + "`  set " + fieldName + "='" + Value + "' Where id=" + id;
            }
            returnStatus = st.executeUpdate(sql);

        } catch (SQLException ex) {

            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + this.tableName).warning(ex.getMessage());
        }


        return returnStatus;
    }

    public int setUpdateValueNocon(String table, String fieldName, String Value, int id) {
        String pid = Integer.toString(id);
        int returndata = this.setFullUpdateValueNocon(table, fieldName, Value, "", pid);
        return returndata;
    }

    public int setUpdateValueNocon(String table, String fieldName, String Value, String Where) {
        int returndata = this.setFullUpdateValueNocon(table, fieldName, Value, Where, "");
        return returndata;

    }

    ////////////////////////////////setUpdateValue
    ////////////////////////////////setUpdateValue
    private int setFullUpdateValue(String table, String fieldName, String Value, String Where, String id) {

        String sql = "";
        int returnStatus = 0;
        this.openCon();
        String return_string = "";
        try {
            st = con.createStatement();
            if (Where != "") {
                sql = "Update  `" + table + "`  set " + fieldName + "='" + Value + "' Where " + Where;
            } else {
                sql = "Update  `" + table + "`  set " + fieldName + "='" + Value + "' Where id=" + id;
            }
            returnStatus = st.executeUpdate(sql);

        } catch (SQLException ex) {
            //utils.outPrint(response, ex.getMessage());
            Logger.getLogger(db.class.getName()).warning(ex.getMessage());
        }
        this.closeCon();

        return returnStatus;
    }

    public int setUpdateValue(String table, String fieldName, String Value, int id) {
        String pid = Integer.toString(id);
        int returndata = this.setFullUpdateValue(table, fieldName, Value, "", pid);
        return returndata;
    }

    public int setUpdateValue(String table, String fieldName, String Value, String Where) {
        int returndata = this.setFullUpdateValue(table, fieldName, Value, Where, "");
        return returndata;

    }

    ////////////////////////////////setUpdateValue
    public String setInsert(String table, String[][] data) {

        String retMsg = "";
        String DBflds = "";
        String valus = "";
        String sql = "";
        for (int i = 0; i < data[0].length; i++) {
            String spli = ",";
            if (i == 0) {
                spli = "";
            }
            DBflds += spli + "`" + data[0][i] + "`";
            valus += spli + "'" + data[1][i] + "'";

        }
        int returnStatus = 0;
        this.openCon();
        String return_string = "";
        try {
            st = con.createStatement();

            sql = "INSERT INTO `" + table + "` (" + DBflds + ") VALUES (" + valus + ")";
            returnStatus = st.executeUpdate(sql);

        } catch (SQLException ex) {
            //
            //       Logger.getLogger("dfgfdg").log(Level.SEVERE, null, ex);


            Logger.getLogger(db.class.getName() + ": this message is from Xact Web :" + table).warning(ex.getMessage());
            //utils.outPrint(response, ex.getMessage());
            retMsg = ex.getMessage();

        }
        this.closeCon();
        return retMsg;//Integer.toString(returnStatus);
    }

////////////////////////////////setUpdateValue
    public String setInsertNocon(String table, String[][] data) {

        String retMsg = "";
        String DBflds = "";
        String valus = "";
        String sql = "";
        for (int i = 0; i < data[0].length; i++) {

            if (!data[0][i].trim().equalsIgnoreCase("") && !data[1][i].trim().equalsIgnoreCase("")) {
                String spli = ",";
                if (i == 0) {
                    spli = "";
                }


                DBflds += spli + "`" + data[0][i] + "`";
                valus += spli + "'" + data[1][i] + "'";
            }


        }
        int returnStatus = 0;

        String return_string = "";
        try {
            st = con.createStatement();

            sql = "INSERT INTO `" + table + "` (" + DBflds + ") VALUES (" + valus + ")";
            returnStatus = st.executeUpdate(sql);

        } catch (SQLException ex) {

            Logger.getLogger(db.class.getName()).log(Level.SEVERE, "sdfsdf", ex);

            retMsg = ex.getMessage();
        }

        return retMsg;//Integer.toString(returnStatus);
    }
}
